package config;

import com.corundumstudio.socketio.SocketIOServer;

/**
 * @Description
 * @Author szw
 * @Data 2019-12-25 14:22
 * @Version 1.0
 */
public class SocketConfig {

    public SocketConfig(){}

    private static int port = 8848;
    private static int linkedCount = 200;
    private static Boolean allowRequest = true;
    private static Integer upgradeTimeOut = 10000;
    private static Integer pingTimeOut = 60000;
    private static Integer pingSpace = 25000;
    private static Integer contextLength = 2071738;
    private static Integer payloadLength = 2071738;

    public static SocketIOServer socketIOServer(){
        com.corundumstudio.socketio.Configuration configuration = new com.corundumstudio.socketio.Configuration();
        configuration.setPort(port);
        configuration.setOrigin(null);//放开跨域
        com.corundumstudio.socketio.SocketConfig socketConfig =  new com.corundumstudio.socketio.SocketConfig();
        socketConfig.setReuseAddress(true);
        configuration.setSocketConfig(socketConfig);
        configuration.setWorkerThreads(linkedCount);
        configuration.setAllowCustomRequests(allowRequest);
        configuration.setUpgradeTimeout(upgradeTimeOut);
        configuration.setPingTimeout(pingTimeOut);
        configuration.setPingInterval(pingSpace);
        configuration.setMaxHttpContentLength(contextLength);
        configuration.setMaxFramePayloadLength(payloadLength);
        return new SocketIOServer(configuration);
    }
}
